package ncov.dao.impl;

import ncov.dao.LocalAuthDao;
import ncov.model.LocalAuth;
import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author WuChangJian
 * @date 2020/6/7 9:32
 */
@Repository
public class LocalAuthDaoImpl implements LocalAuthDao {

    @Autowired
    private SessionFactory sessionFactory;
    private Session getSession() {
        return sessionFactory.getCurrentSession();
    }

    @Override
    public LocalAuth queryById(Integer id) {
        return null;
    }

    @Override
    public List<LocalAuth> queryAllByLimit(int offset, int limit) {
        return null;
    }

    @Override
    public List<LocalAuth> queryAll(LocalAuth localAuth) {
        Session session = getSession();
        Criteria criteria = session.createCriteria(LocalAuth.class);
        criteria.add(Restrictions.eq("username", localAuth.getUsername()));
        criteria.add(Restrictions.eq("password", localAuth.getPassword()));
        return criteria.list();
    }

    @Override
    public int insert(LocalAuth localAuth) {
        return 0;
    }

    @Override
    public int update(LocalAuth localAuth) {
        getSession().update(localAuth);
        return 0;
    }

    @Override
    public int deleteById(Integer id) {
        return 0;
    }
}
